package com.my.action;

import java.io.IOException;
import java.util.Map;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.my.util.MD5Util;
@Controller
@RequestMapping("Login")
public class Login extends mybaseAction{
	@RequestMapping("login")
    public void login() throws IOException { 
		response.setContentType("application/json; charset=utf-8"); 
    	String sqlId=request.getParameter("sqlId");
    	String sqlParam=request.getParameter("sqlParam");
    	JSONObject param=JSONObject.fromObject(sqlParam);
    	param.put("password", MD5Util.string2MD5(param.get("password").toString()));
    	Map<String,Object> map=prdDbService.selectOne(sqlId,param);
    	JSONObject json=new JSONObject();
    	if(map!=null){
    		session.setAttribute("userInfo", map);
    		json=JSONObject.fromObject("{state:'success'}");
    		response.getWriter().write(json.toString());
    	}else{
    		json=JSONObject.fromObject("{state:'error',msg:'用户名或密码错误！'}");
    		response.getWriter().write(json.toString());
    	}
    }
}
